﻿
@model KRM.Core.CreateTrigger
@{
    ViewBag.Title = "Scenario";
    Layout = "~/Views/Shared/_Layout.cshtml";
    int page = 1;

    if (Request.QueryString["p"] != null)
    {
        page = Convert.ToInt32(Request.QueryString["p"]);

    }

    int itemPerPage = 20;
    List<KRM.Core.tblScenarioTask> lstTask = ViewBag.lstTask;
    int pagingCount = Convert.ToInt32(Math.Ceiling((lstTask.Count / (float)itemPerPage)));
    var listPaging = lstTask.Skip((page - 1) * itemPerPage).Take(itemPerPage).ToList();
}

<div id="viewtrigger" class="modal hide fade view-trigger" tabindex="-1" role="dialog" aria-labelledby="viewtrigger" aria-hidden="true">
    <div class="modal-body body-viewtrigger">
        <div class="row-fluid">
            <div class="ajax-loading"></div>
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>
<div id="createtrigger" class="modal hide fade create-trigger" tabindex="-1" role="dialog" aria-labelledby="createtrigger" aria-hidden="true">
    @using (Html.BeginForm("Createtrigger", "Scenario", FormMethod.Post, new { id = "frCreateTrigger", style="margin: 0" }))
    {
        @Html.ValidationSummary(true)
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h5 id="myModalLabel">Create trigger</h5>
        </div>
        <div class="modal-body body-createtrigger">
            <div class="msg-trigger"></div>
            <div class="bodyhf-createtrigger">
                <input type="hidden" value="1" name="TaskId" id="hfTaskid" />
                <input type="hidden" name="DayInWeek" id="hfdayinweek" />
                <input type="hidden" name="Months" id="hfmonths" />
                <input type="hidden" name="DaysInMonths" id="hfdaysinmonths" />

                <div class="row-fluid">
                    <div class="span1"></div>
                    <div class="span3">Run type</div>
                    <div class="span8">
                        <select name="Index" id="runtype">
                            <option value="4">One time</option>
                            <option value="1">Daily</option>
                            <option value="2">Weekly</option>
                            <option value="3">Monthly</option>
                        </select>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span1"></div>
                    <div class="span3">Start time</div>
                    <div class="span8">
                        <div id="datetimepicker2" class="input-append">
                            <input data-format="MM/dd/yyyy HH:mm:ss PP" type="text" name="datestart" value="@DateTime.Now" id="datestart" style="width: 173px;" required="required"/>
                            <span class="add-on">
                                <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span1"></div>
                    <div class="span3">Enable</div>
                    <div class="span8">
                        @Html.CheckBoxFor(model => model.Enable, new { @checked = "checked" })
                    </div>
                </div>
                <div class="row-fluid ctr-daily">
                    <div class="span1"></div>
                    <div class="span3">Recur every</div>
                    <div class="span8">
                        <input type="number" name="Every" id="every" class="input-small" value="1" disabled="disabled" required="required">
                        days
                    </div>
                </div>
                <div class="row-fluid ctr-weekly">
                    <div class="span1"></div>
                    <div class="span3">
                        Select days<br />
                        <small>ctrl + click to select many</small>
                    </div>
                    <div class="span8">
                        <select multiple="multiple" id="dayinweek" disabled="disabled" required="required">
                            <option value="1">Monday</option>
                            <option value="2">Tuesday</option>
                            <option value="3">Wednesday</option>
                            <option value="4">Thursday</option>
                            <option value="5">Friday</option>
                            <option value="6">Staturday</option>
                            <option value="0">Sunday</option>
                        </select>
                    </div>
                </div>
                <div class="row-fluid ctr-monthly">
                    <div class="span1"></div>
                    <div class="span3">
                        Months<br />
                        <small>ctrl + click to select many</small>
                    </div>
                    <div class="span8">
                        <select multiple="multiple" id="months" disabled="disabled" required="required">
                            <option value="1">January</option>
                            <option value="2">February</option>
                            <option value="3">March</option>
                            <option value="4">April</option>
                            <option value="5">May</option>
                            <option value="6">June</option>
                            <option value="7">July</option>
                            <option value="8">August</option>
                            <option value="9">September</option>
                            <option value="10">October</option>
                            <option value="11">November</option>
                            <option value="12">December</option>
                        </select>
                    </div>
                </div>
                <div class="row-fluid ctr-monthly">
                    <div class="span1"></div>
                    <div class="span3">
                        Days<br />
                        <small>ctrl + click to select many</small>
                    </div>
                    <div class="span8">
                        <select multiple="multiple" id="daysinmonths" disabled="disabled" required="required">
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                            <option value="13">13</option>
                            <option value="14">14</option>
                            <option value="15">15</option>
                            <option value="16">16</option>
                            <option value="17">17</option>
                            <option value="18">18</option>
                            <option value="19">19</option>
                            <option value="20">20</option>
                            <option value="21">21</option>
                            <option value="22">22</option>
                            <option value="23">23</option>
                            <option value="24">24</option>
                            <option value="25">25</option>
                            <option value="26">26</option>
                            <option value="27">27</option>
                            <option value="28">28</option>
                            <option value="29">29</option>
                            <option value="30">30</option>
                            <option value="31">31</option>
                        </select>
                    </div>
                </div>
                <p class="p-advance"><a href="javascript:;" title="click to show advance option">Advance</a></p>
                <div class="panel-advance">
                    <div class="row-fluid">
                        <div class="span1"></div>
                        <div class="span3">
                            <input type="checkbox" class="loop-task" />
                            Loop task in
                        </div>
                        <div class="span8">
                            <input type="text" name="Minutes" class="minutes" value="15" disabled="disabled" style="width: 20px" required="required" />
                            <select name="ChooseMinutes" class="choose-minutes" style="width: 80px" disabled="disabled">
                                <option value="1">Minutes</option>
                                <option value="60">Hours</option>
                                <option value="1440">day</option>
                            </select>
                            on
                        <input type="text" name="Hours" value="1" style="width: 20px" disabled="disabled" class="hours" required="required" />
                            <select name="ChooseHours" style="width: 80px" disabled="disabled" class="choose-hours">
                                <option value="1">Minutes</option>
                                <option value="60" selected="selected">Hours</option>
                                <option value="1440">day</option>
                            </select>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span1"></div>
                        <div class="span3">
                            <input type="checkbox" class="stop-task" />
                            Stop task if runs over
                        </div>
                        <div class="span8">
                            <input type="text" name="StopMinutes" class="stop-minutes" value="1" style="width: 20px" disabled="disabled" required="required" />
                            <select name="ChooseStopMinutes" style="width: 80px" disabled="disabled" class="choose-stop-minutes">
                                <option value="1">Minutes</option>
                                <option value="60" selected="selected">Hours</option>
                                <option value="1440">day</option>
                            </select>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span1"></div>
                        <div class="span3">
                            <input type="checkbox" class="expired" />
                            Time expired
                        </div>
                        <div class="span8">
                            <div id="datetimepicker3" class="input-append">
                                <input data-format="MM/dd/yyyy HH:mm:ss PP" type="text" name="Expireddate" value="@DateTime.Now" class="expireddate" style="width: 173px;" disabled="disabled" required="required"/>
                                <span class="add-on">
                                    <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="submit" class="btn btn-primary btn-create-trigger">Create</button>
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    }
</div>

<div class="container-fluid">
    <div id="modaltoggle"></div>
    <div class="page-header"></div>
    @if (Request["msg"] != null && Request["msg"].Equals("success"))
    {
        <div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>Success!</strong>
        </div>
    }
    else if (Request["msg"] != null && Request["msg"].Equals("error"))
    {
        <div class="alert alert-error">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>Error!</strong>
        </div>
    }
    <div class="row-fluid">
        <table class="table table-hover table-bordered table-fix">
            <thead>
                <tr class="task-filter">
                    <th><span col="id">ID</span></th>
                    <th><span col="taskname">Task name</span></th>
                    <th>Next run
                    </th>
                    <th>ListOfUsers</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in listPaging)
                {
                    <tr>
                        <td>
                            @item.TaskID
                        </td>
                        <td>
                            @item.TaskName
                        </td>
                        <td>
                            @item.GetNextRunClosest
                        </td>
                        <td>
                            @item.ListOfUsers
                        </td>
                        <td><a onclick="viewTrigger(@item.TaskID)" id="aaa" data-toggle="modal" href="#viewtrigger">View trigger</a> | <a onclick="createTrigger(@item.TaskID)" data-toggle="modal" href="#createtrigger">Add trigger</a></td>
                    </tr>
                }
            </tbody>
        </table>
        <input type="hidden" id="hfSortCol" value='@(Request["sortcol"] ?? "id")'>
        <input type="hidden" id="hfSortDes" value="@(Request["sortdes"] ?? "desc")">
        <div class="paging">
            <a href="/scenario">«</a>
            <span>
                @for (int j = page - 3; j <= page + 3; j++)
                {
                    if (j > 0 && j <= pagingCount)
                    {
                        if (j == page)
                        {
                    <a href="/scenario?p=@j" class="page-active">@j</a>
                        }
                        else
                        {
                    <a href="/scenario?p=@j">@j</a>
                        }

                    }
                }
            </span>
            <a href="/scenario?p=@pagingCount">»</a>
        </div>
    </div>
</div>
